package com.soft.controller;

import com.soft.entity.Department;
import com.soft.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    @RequestMapping("/hello")
    public String hello() {
        return "Hello,Saul Goodman!";
    }
    @RequestMapping("/queryAll")
    public List<Department> queryAll(){
        return departmentService.queryAll();
    }
    @RequestMapping("/insert")
    public String insert(String name,String address){
        int num=departmentService.insert(name,address);
        if(num>0){
            return "成功插入系"+name;
        }
        else {
            return "插入失败";
        }
    }
    @RequestMapping("/deleteById")
    public String deleteById(int id){
        int num=departmentService.deleteById(id);
        if(num>0){
            return "Delete Sucessfully";
        }
        else {
            return "Delete Failed";
        }
    }
    @RequestMapping("/queryDepartmentNameByStudentName")
    public String queryDepartmentNameByStudentName(String studentName){
        return studentName+"所属的系为"+departmentService.queryDepartmentNameByStudentName(studentName);
    }
    @RequestMapping("/countStudentNumbersByDepartmentName")
    public String countStudentNumbersByDepartmentName(String departmentName){
        return departmentName+"的人数为"+departmentService.countStudentNumbersByDepartmentName(departmentName);
    }



}
